export default {
  namespaced:'true',
  
  // 数据
  state:() =>({
    address:JSON.parse(uni.getStorageSync('address') || "{}"),
    token:uni.getStorageSync('token') ||　'',
    userinfo:{nickName: "成天乐",avatarUrl: "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTIs32mhKITqFuVhPLyEWYje97CD0YtzTty97iaTNWsvOYicVYPra0uibfmgHTaNxlPe3p07jianu1cV2w/132"},
    // 重定向object对象
    redirectInfo:null
    
  }),
  
  // 方法
  mutations:{
    // 更新收货地址
    updateAddress(state,address){
      state.address = address
      this.commit('m_user/saveAddressToStorage')
    },
    
    // 将地址定义持久化
    saveAddressToStorage(state){
      uni.setStorageSync('address',JSON.stringify(state.address))
    },
    
    // 更新用户数据
    updateUserInfo(state,userinfo){
      state.userinfo = userinfo
      this.commit('m_user/saveUserInfoStorage')
    },
    
    //用户数据持久化
    saveUserInfoStorage(state){
      uni.getStorageSync('userinfo',JSON.stringify(state.userinfo))
    },
    
    // 更新token
    updateToken(state,token){
      state.token = token
      this.commit('m_user/saveTokenToStorage')
    },
    
    // token本地持久化
    saveTokenToStorage(state){
      uni.setStorageSync('token',state.token)
    },
    
    //传递重定向后的页面信息
     updateRedirectInfo(state,info){
       state.redirectInfo = info
       console.log(state.redirectInfo)
     }
  },
  
  
  getters:{
    addstr(state){
      if(!state.address.provinceName) return ''
      return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
    }
  }
}